import { isString, isNumber, multipleChecked, radioChecked, isArray, guID } from "@/common.js"
// 调整字段
export const changeField = function (e, field) {
  e = e || ''
  const value = isString(e) || isNumber(e) || isArray(e) ? e : e.target.value
  // 更新右侧的值
  const item = {...this.item, [field]: value}
  this.$emit('setItem', item)
  // 更新整体表单的值
  const formData = _.searchCover(this.formData, {id: this.item.id}, v => ({...v, [field]: value}))
  this.$emit('setFormData', formData)
}
// 改变当前input输入框的数据
export const changeCurVal = function (e, curItem) {
  e = e || ''
  let value = isString(e) || isNumber(e) || isArray(e) ? e : e.target.value
  const children = _.searchCover(this.item.children, {id: curItem.id}, v => ({...v, span: value}))
  this.changeField(children, 'children')
}
// 删除
export const delCurSpan = function (curItem) {
  const children = this.item.children.filter(v => v.id != curItem.id)
  this.changeField(children, 'children')
}
// 添加
export const addCurSpan = function () {
  const children = [...this.item.children, {id: guID(),span: 50,isShow: true}]
  this.changeField(children, 'children')
}